import { crudApi } from './common'
import type { MenuItem, MenuQuery, MenuForm } from '@/types/menu'
import type { PageResponse } from '@/types/api'

// 菜单API基础路径
const MENU_BASE_URL = '/system/menu'

// 获取菜单列表
export const getMenuListApi = (): Promise<MenuItem[]> => {
  return crudApi.getList<MenuItem>(`${MENU_BASE_URL}/list`)
}

// 获取菜单树
export const getMenuTreeApi = (): Promise<MenuItem[]> => {
  return crudApi.getList<MenuItem>(`${MENU_BASE_URL}/tree`)
}

// 获取菜单分页列表
export const getMenuPageApi = (params: MenuQuery): Promise<PageResponse<MenuItem>> => {
  return crudApi.getPageList<MenuItem>(`${MENU_BASE_URL}/page`, params)
}

// 获取菜单详情
export const getMenuDetailApi = (id: number): Promise<MenuItem> => {
  return crudApi.getDetail<MenuItem>(MENU_BASE_URL, id)
}

// 新增菜单
export const addMenuApi = (data: MenuForm): Promise<void> => {
  return crudApi.create(MENU_BASE_URL, data)
}

// 修改菜单
export const updateMenuApi = (data: MenuForm): Promise<void> => {
  return crudApi.update(MENU_BASE_URL, data)
}

// 删除菜单
export const deleteMenuApi = (ids: number[]): Promise<void> => {
  return crudApi.delete(MENU_BASE_URL, ids)
}

// 获取菜单选项
export const getMenuOptionsApi = (): Promise<MenuItem[]> => {
  return crudApi.getList<MenuItem>(`${MENU_BASE_URL}/options`)
}
